;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-advanced-reader.ss" "lang")((modname ex1.18) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ())))
(define (double a) (* 2 a))
(define (halve a)  (/ a 2))

(define (use-iter-multiply a b)
  (iter-multiply a b 0))

(define (iter-multiply a b result)
  (cond ((= b 0) result)
        ((even? b) (iter-multiply (double a) (halve b) result))
        (else (iter-multiply a (- b 1) (+ result a)))))